﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SIPDTO;
using System.Data;

namespace SIP
{
    public partial class ListadoCanton : System.Web.UI.Page
    {

        #region ** Declaración de variables
        List<dtoCanton> _dtcanton = new List<dtoCanton>();
        SIPBLL.SIPBLL _bll = new SIPBLL.SIPBLL();
        int _index;
        GridViewRow _row;
        dtoCanton _dtocanton = new dtoCanton();
        dtoError _resp = new dtoError();

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CargarCanton();
                Session["Crear"] = true;
            }
        }

        private void CargarCanton()
        {
            _dtcanton = _bll.ObtenerTodosCantones();
            Grid.DataSource = _dtcanton;
            Grid.DataBind();
        }


        protected void Grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Modificar")
            {
                _index = Convert.ToInt32(e.CommandArgument);
                _row = Grid.Rows[_index];
                Session["idCanton"] = _row.Cells[0].Text;
                Session["Crear"] = false;
                Response.Redirect("Canton.aspx");
            }
            if (e.CommandName == "Eliminar")// Inactiva el registro de la parroquia
            {
                _index = Convert.ToInt32(e.CommandArgument);
                _row = Grid.Rows[_index];
                Session["idCanton"] = _row.Cells[0].Text;
                _dtocanton.Identificacion = Convert.ToInt16(Session["idCanton"]);
                _dtocanton.Estado = false;
                _resp = _bll.InactivarCanton(_dtocanton);
                if (_resp.IdError == 100)
                {
                    WebMsgBox.Show(_resp.Mensaje);
                    CargarCanton();
                }
                else
                {
                    WebMsgBox.Show(_resp.Mensaje);
                }
            }

        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session["Crear"] = true;
            Response.Redirect("Canton.aspx");
        }

    }
}